package com.openvas.controller;

import java.util.List;
//    import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.openvas.commons.common.annotation.Log;
import com.openvas.commons.common.enums.BusinessType;
import com.openvas.domain.TableVulnerabilities;
import com.openvas.service.ITableVulnerabilitiesService;
import com.openvas.commons.common.core.controller.BaseController;
import com.openvas.commons.common.core.domain.AjaxResult;

import com.openvas.commons.common.core.page.TableDataInfo;

/**
 * 漏洞Controller
 * 
 * @author ruoyi
 * @date 2021-11-04
 */
@Controller
@RequestMapping("/api/vulnerabilities")
public class TableVulnerabilitiesController extends BaseController
{
    private String prefix = "system/vulnerabilities";

    @Autowired
    private ITableVulnerabilitiesService tableVulnerabilitiesService;

   //  @RequiresPermissions("system:vulnerabilities:view")
    @GetMapping()
    public String vulnerabilities()
    {
        return prefix + "/vulnerabilities";
    }

    /**
     * 查询漏洞列表
     */
   //  @RequiresPermissions("system:vulnerabilities:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TableVulnerabilities tableVulnerabilities)
    {
        startPage();
        List<TableVulnerabilities> list = tableVulnerabilitiesService.selectTableVulnerabilitiesList(tableVulnerabilities);
        return getDataTable(list);
    }

    /**
     * 导出漏洞列表
     */
   //  @RequiresPermissions("system:vulnerabilities:export")
    @Log(title = "漏洞", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TableVulnerabilities tableVulnerabilities)
    {
        List<TableVulnerabilities> list = tableVulnerabilitiesService.selectTableVulnerabilitiesList(tableVulnerabilities);
//        ExcelUtil<TableVulnerabilities> util = new ExcelUtil<TableVulnerabilities>(TableVulnerabilities.class);
//        return util.exportExcel(list, "漏洞数据");
        return null;
    }

    /**
     * 新增漏洞
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存漏洞
     */
   //  @RequiresPermissions("system:vulnerabilities:add")
    @Log(title = "漏洞", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TableVulnerabilities tableVulnerabilities)
    {
        return toAjax(tableVulnerabilitiesService.insertTableVulnerabilities(tableVulnerabilities));
    }

    /**
     * 修改漏洞
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TableVulnerabilities tableVulnerabilities = tableVulnerabilitiesService.selectTableVulnerabilitiesById(id);
        mmap.put("tableVulnerabilities", tableVulnerabilities);
        return prefix + "/edit";
    }

    /**
     * 修改保存漏洞
     */
   //  @RequiresPermissions("system:vulnerabilities:edit")
    @Log(title = "漏洞", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TableVulnerabilities tableVulnerabilities)
    {
        return toAjax(tableVulnerabilitiesService.updateTableVulnerabilities(tableVulnerabilities));
    }

    /**
     * 删除漏洞
     */
   //  @RequiresPermissions("system:vulnerabilities:remove")
    @Log(title = "漏洞", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tableVulnerabilitiesService.deleteTableVulnerabilitiesByIds(ids));
    }
}
